package com.hilinos.ftp.api;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hilinos.common.common.ReturnCode;
import com.hilinos.common.util.AssertUtils;
import com.hilinos.ftp.anno.Auth;
import com.hilinos.ftp.api.qo.UserListQo;
import com.hilinos.ftp.api.vo.UserLoginVo;
import com.hilinos.ftp.pojo.UserPojo;
import com.hilinos.ftp.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("user")
public class UserApi {

    @Autowired
    private UserService userService;

    @PostMapping("login")
    private UserLoginVo login(HttpServletResponse response, String accountId, String password) {
        AssertUtils.isNotEmpty(accountId, ReturnCode.NORMAL_PARAM_LOST_ERROR.respMsg("账号不能为空"));
        AssertUtils.isNotEmpty(password, ReturnCode.NORMAL_PARAM_LOST_ERROR.respMsg("密码不能为空"));
        return userService.login(accountId, password, response);
    }

    /**
     * 查询用户列表
     *
     * @return
     */
    @Auth("admin")
    @GetMapping("admin/userList")
    public Page<UserPojo> userList(UserListQo qo) {
        return userService.userList(qo);
    }

    /**
     * 查询用户信息
     *
     * @return
     */
    @GetMapping("gen/detail")
    public UserPojo detail() {
        return userService.detail(BaseApi.getUser());
    }

}
